package com.mvu.banana.common.validation;

import com.google.gwt.regexp.shared.RegExp;

import java.util.Collection;

/**
 * Created by mvu at 5/21/11 12:46 PM
 * To change this template use File | Settings | File Templates.
 */
public class Validator {
  private static final RegExp EMAIL_PATTERN = RegExp.compile("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b", "i");

  public static boolean isNotNull(Object value){
    return value != null;
  }

  public static boolean isNotNull(Enum value){
    return value.ordinal() > 0;
  }

  public static boolean isNotEmpty(Collection values){
    return values.size() > 0;
  }

  public static boolean isNotBlank(String value){
    return value != null && value.trim().length() > 0;
  }

  public static boolean isLength(String value, int min, int max){
    return isNotNull(value) && value.trim().length() >= min && value.trim().length() <= max;
  }

  public static boolean isEmail(String value){
    return EMAIL_PATTERN.test(value);
  }

  public static boolean isMin(Long value, long min){
    return isNotNull(value) && value >= min;
  }

  public static boolean isMin(Integer value, int min){
    return isNotNull(value) && value >= min;
  }

  public static boolean isMax(Long value, long max){
    return isNotNull(value) && value <= max;
  }

  public static boolean isMax(Integer value, int max){
    return isNotNull(value) && value <= max;
  }
}
